<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
  <h4 class="modal-title" id="extension-modal-label">选择试听班级</h4>
</div>
<div class="modal-body editor-body-sm">
	<table  data-click-to-select="true" id="table-classes" class="bootstrap-table">
	</table>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
  <button type="button" class="btn btn-primary" onclick="handlerClasses()">确认</button>
</div>

<script type="text/javascript">
<!--
	jQuery(function(){
		createData();
		handlerSuccess();
	})
	
	function createData(){
		var date = promisedate.substring(0,10);
		var time = new Date(Date.parse(date.replace(/-/g, '/')));
		var weekList = ['周日','周一','周二','周三','周四','周五','周六'];
		var week = 	weekList[time.getDay()];
		var datas = getData(date,week);
		var column = getColumn();
		jQuery("#table-classes").bootstrapTable({
			columns:column,
		  data:datas,
		});
	}
	
	function getColumn(){
		var colums = [{checkbox:true},
		              {field: 'name', title: '班级名称', align: 'center'},
									{field: 'room', title: '所在教室', align: 'center'},
									{field: 'toplimit', title: '学员上限', align: 'center'},
									{field: 'trylimit', title: '试听上限', align: 'center'}
		];
		return colums;
	}  
	
	
	function getData(date,week){
		var classesdata = {};
		jQuery.ajaxsend({
			url:"/miwawa/{dbname}/common/procedure/call".replace("{dbname}",dbname),
			async:false,
			data:{
				"name":"pro_saas_canlisten",
				"params":{
					"_current":date,
					"_week":week
				}
			},
			success:function(data){
				classesdata =  data.rows;
			}
		});		
		return classesdata;
	}
	
	// 试听分班确认
	function handlerClasses(){
		var rows = jQuery("#table-classes").bootstrapTable("getSelections");
		if(rows.length == 0){
			jQuery.message.warning("请选择要试听的班级！");
		}else if(rows[0].surplus == 0){
			jQuery.message.warning("该班级试听余额已用完，请选择其它试听班级！");
		}else{
			var selected = jQuery("#extension-modal").data("selectedRow");
			jQuery.ajaxsend({
				url:"/miwawa/{dbname}/common/save".replace("{dbname}", dbname),
				data:{
					"entityClass":"com.app.miwawa.api.esm.entity.customer.Audition",
					"bean":{
						"classes":rows[0].name,
						"classesid":rows[0].id,
						"teacher":rows[0].teacher,
						"bespokeid":selected.id,
						"promiseDate":selected.promiseDate,
						"status":"0",
						"invalid":"F"
					}
				},
				success:function(data){
					if(data) {
						jQuery("#table-bespoke").bootstrapTable("refresh");
						jQuery("#extension-modal").modal('hide');
					}
				}
			});
		}
	}
//-->
</script>